import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution380 {

    Map<Integer,Integer> map=new HashMap<>();
    List<Integer> f=new ArrayList<>();

    public Solution380() {

    }

    public boolean insert(int val) {
        if (map.containsKey(val)){
            return false;
        }else{
            f.add(val);
            map.put(val,f.size()-1);
            return true;
        }
    }

    public boolean remove(int val) {
        if (!map.containsKey(val)){
            return false;
        }else{
            int p=map.get(val);
            if (p!=f.size()-1){
                f.set(p,f.get(f.size()-1));
                map.put(f.get(f.size()-1),p);
            }
            f.remove(f.size()-1);
            map.remove(val);
            return true;
        }
    }

    public int getRandom() {
        int r=(int)(Math.random()*f.size());
        return f.get(r);
    }

    public static void main(String[] args) {
        Solution380 solution380=new Solution380();
        System.out.println(solution380.insert(1));
        System.out.println(solution380.remove(2));
        System.out.println(solution380.insert(2));
        System.out.println(solution380.getRandom());
        System.out.println(solution380.remove(1));
        System.out.println(solution380.insert(2));
        System.out.println(solution380.getRandom());
    }
}
